/**
  ******************************************************************************
  * @file    main.h
  * @author  Application Team
    * @Version V1.0.0
  * @Date    1-April-2019    
  * @brief   Header for main.c file.
  *          This file contains the common defines of the application.
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LPUART_H
#define __LPUART_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "cx32l003_hal.h"
#include "cx32l003_starterkit.h"

/* Private includes ----------------------------------------------------------*/
#include "io_mapping.h"
#include "log.h"
#include "util.h"
#include <stdbool.h>

/* Exported constants ---------------------------------------------------------*/
#define LPUARTx                                             LPUART
#define LPBAUDRATE                                          115200
#define LPUARTx_TX_PORT                                     GPIOC
#define LPUARTx_TX_PIN                                      GPIO_PIN_5
#define LPUARTx_RX_PORT                                     GPIOC
#define LPUARTx_RX_PIN                                      GPIO_PIN_6
#define LPUARTx_TX_ALTERNATE_AFn                            GPIO_AF5_LPUART_TXD
#define LPUARTx_RX_ALTERNATE_AFn                            GPIO_AF5_LPUART_RXD

#define LPUARTx_IRQn                                        LPUART_IRQn

#define LENGTH                                                    10
#define TIMEOUT_MAX                                            0xFFFFFFFF

/* Exported macros-------------------------------------------------------------*/
#define __HAL_RCC_LPUARTx_CLK_ENABLE()                  __HAL_RCC_LPUART_CLK_ENABLE()    
#define __HAL_RCC_LPUARTx_TXGPIO_CLK_ENABLE()      __HAL_RCC_GPIOC_CLK_ENABLE()    
#define __HAL_RCC_LPUARTx_RXGPIO_CLK_ENABLE()      __HAL_RCC_GPIOC_CLK_ENABLE()    
 
#define LPUART_RX_BUF_LEN       100
#define LPUART_TX_BUF_LEN       50

typedef struct LPUART_buff{
    
    uint8_t UART_RX_Buff[LPUART_RX_BUF_LEN];
    uint8_t UART_RX_LEN;
    uint8_t UART_RX_FRAME;
    
    uint8_t UART_TX_Buff[LPUART_TX_BUF_LEN];
    uint8_t UART_TX_LEN;
    uint8_t UART_TX_FRAME;
    
}lpuart_buff_Value;


/* Exported functions prototypes ---------------------------------------------*/
extern LPUART_HandleTypeDef sLPUartxHandle;

extern lpuart_buff_Value  lpuart_buff;

void Error_Handler(void);

void HAL_LPUART_INIT(void);

void LPUart_Send_data( uint8_t *Data,uint16_t lend);

void LPUart_Send_Byte( uint8_t Data);

void LPUart_RxXfertime_task(LPUART_HandleTypeDef *hlpuart);

void clr_sUART_lpuart_buff(void);

/* Private defines -----------------------------------------------------------*/

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */

